﻿using System;
using System.Collections.Generic;
using System.Linq;
using DotNetNuke.Entities.Users;
using DotNetNuke.Entities.Profile;
using DotNetNuke.Services.Localization;

namespace WESNet.DNN.Modules.UserExport
{
    public class ProfileProperty
    {

        private static string AllUsers = Localization.GetString("Public", Localization.SharedResourceFile);
        private static string MembersOnly = Localization.GetString("MembersOnly", Localization.SharedResourceFile);
        private static string AdminOnly = Localization.GetString("AdminOnly", Localization.SharedResourceFile);
        private static string FriendsAndGroups = Localization.GetString("FriendsGroups", Localization.SharedResourceFile);

        public int PropertyDefinitionID { get; private set; }
        public string PropertyName { get; private set; }
        public string PropertyCategory { get; private set; }
        public UserVisibilityMode DefaultVisibility { get; private set; }
        public bool Required { get; private set; }
        public string DefaultValue { get; private set; }
        public bool IsUserInfoProperty { get; private set; }
        public bool Selected { get; set; }

        public string LocalizedVisibility
        {
            get
            {
                return GetLocalizedVisibility(DefaultVisibility);
            }
        }

        public ProfileProperty(ProfilePropertyDefinition ppd)
        {
            PropertyDefinitionID = ppd.PropertyDefinitionId;
            PropertyName = ppd.PropertyName;
            PropertyCategory = ppd.PropertyCategory;
            DefaultValue = ppd.DefaultValue;
            DefaultVisibility = ppd.DefaultVisibility;
            Required = ppd.Required;
        }

        public ProfileProperty(int propertyDefinitionID, string propertyName, UserVisibilityMode defaultVisibility)
        {
            PropertyDefinitionID = propertyDefinitionID;
            PropertyName = propertyName;
            IsUserInfoProperty = true;
            DefaultVisibility = defaultVisibility;
            Required = true;
        }

        public override string ToString()
        {
            return PropertyName;
        }

        public static string GetLocalizedVisibility (UserVisibilityMode defaultVisibility)
        {
            string text = "";

            switch (defaultVisibility)
            {
                case UserVisibilityMode.AllUsers:
                    text = AllUsers;
                    break;
                case UserVisibilityMode.MembersOnly:
                    text = MembersOnly;
                    break;
                case UserVisibilityMode.AdminOnly:
                    text = AdminOnly;
                    break;
                case UserVisibilityMode.FriendsAndGroups:
                    text = FriendsAndGroups;
                    break;
            }
            return text;
        }
    }
}